package org.jeecg.modules.app.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.dongliu.apk.parser.ApkFile;
import net.dongliu.apk.parser.bean.ApkMeta;
import net.dongliu.apk.parser.bean.UseFeature;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.util.UUIDGenerator;
import org.jeecg.modules.app.bo.*;
import org.jeecg.modules.app.dto.*;
import org.jeecg.modules.app.vo.ContentVo;
import org.jeecg.modules.app.vo.ModuleVo;
import org.jeecg.modules.minqing.entity.*;
import org.jeecg.modules.minqing.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.*;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: 招商工作动态
 * @Author: jeecg-boot
 * @Date: 2020-01-08
 * @Version: V1.0
 */
@Slf4j
@Api(tags = "app接口")
@RestController
@RequestMapping("/app")
public class AppController {
    @Value(value = "${jeecg.path.upload}")
    private String uploadpath;
    @Autowired
    private IProjectService projectService;
    @Autowired
    private IIndustryChainService industryChainService;
    @Autowired
    private IFavorablePolicyService favorablePolicyService;

    @Autowired
    private IDynamicNewsService dynamicNewsService;

    @Autowired
    private IAnnouncementService announcementService;
    @Autowired
    private IPraiseLogService praiseLogService;
    @Autowired
    private IResourceManageService resourceManageService;

    @Autowired
    private IMemberService memberService;

    @Autowired
    private IOtherServiceService otherServiceService;
    @Autowired
    private IDepartmentsService departmentsService;
    @Autowired
    private IIndustryTypeService industryTypeService;
    @Autowired
    private IPlotService plotService;


    @ApiOperation(value = "县情简介", notes = "县情简介")
    @PostMapping(value = "/queryCountyInfo")
    public AppResult<?> queryCountyInfo() {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("video", "https://apd-bbe5fd016aaa464b907f9e2af47d0c1d.v.smtcdns.com/om.tc.qq.com/A_zNyvZjtd0mUc_qhAjxKvvCldjNwWNanLeDi692aR6s/uwMROfz2r5zCIaQXGdGnC2dfDmavB6NbsWKJAiRTQBPbT70a/s0872lvzo9p.mp4?sdtfrom=v1010&guid=fd96bafbcfa43f2512e523c59e04cfbb&vkey=17D32749EA56B9CE6B508AC04000CC06A6F7C01504EF76CA5F76D77B9DEC90F25B6F3A4DFB236939856C837B46D7BE5AE13630D39828D7E325B8CD9EC1CC1DC6842F5C0F139B806667DE582B202B7C6385758F777DCA32ABE1ADD1285E7F883898181FF2A215EB9D32ABE1FC9E36EB02E21585797289CBC102C7DE8C7CBD9108");
        List<String> imgList = new ArrayList<>();
        imgList.add("files/20191101/1572544163355.jpg");
        imgList.add("files/20191101/bbafe3793dbf4ec231c7af46e17b9f0_1572544168527.jpg");
        imgList.add("files/20191101/DJI_0021-1_1572542693961.jpg");
        map.put("imgList", imgList);
        map.put("introduction", "闽清，简称“梅”，因闽江与境内主干流梅溪交融，“江水浊、溪水清”而得名。古老的闽江和秀丽的梅溪孕育了这块福祥宝地，滋润着1466平方公里的沃土和32万百姓。全县辖11镇5乡291个村居，耕地面积26.41万亩，水口库区水面1.5万亩，森林覆盖率66.41%，有高岭土等23种丰富的矿产资源。2015年被评为省级生态县和省级园林县城，2016年获得“中国温泉之乡”称号。");
        return AppResult.ok(map);
    }

    @ApiOperation(value = "获取自然资源/农业 详情", notes = "获取自然资源 详情")
    @PostMapping(value = "/queryProjectNaturalById")
    public AppResult<?> queryProjectNaturalById(@RequestBody IdDto dto) {
        Project project = projectService.getById(dto.getId());
        if (ObjectUtil.isEmpty(project)) {
            return AppResult.error("无法查看详情");
        }
        if (!"1".equals(project.getIndustryType()) && !"2".equals(project.getIndustryType())){
            return AppResult.error("无法查看详情");
        }
        Map<String, Object> map = new LinkedHashMap<>();
        List<String> imgList = new ArrayList<>();
        String module = project.getProjectMoudle();
        if (StringUtils.isBlank(module)){
            return AppResult.error("无法查看详情");
        }
        AppResBO appResBO = JSONUtil.toBean(module,AppResBO.class);
        imgList.add(appResBO.getAppImg());
        map.put("imgList", imgList);
        map.put("introduction", appResBO.getAppCotent());
        return AppResult.ok(map);
    }




    @ApiOperation(value = "项目推介-首页信息", notes = "项目推介-首页信息")
    @PostMapping(value = "/index")
    public AppResult<?> index() {
        Map<String, Object> map = new LinkedHashMap<>();
        List<Project> projectList = projectService.list(new LambdaQueryWrapper<Project>().last("limit 5"));
        //热点公告
        LambdaQueryWrapper<Announcement> annqw = new LambdaQueryWrapper<>();
        annqw.eq(Announcement::getHot, "1");
        List<Announcement> hotAdList = announcementService.list(annqw);
        List<String> imgList = new ArrayList<>();
        imgList.add("files/20191101/1572544163355.jpg");
        imgList.add("files/20191101/bbafe3793dbf4ec231c7af46e17b9f0_1572544168527.jpg");
        imgList.add("files/20191101/DJI_0021-1_1572542693961.jpg");
        map.put("imgList", imgList);
        map.put("hotAdList", hotAdList);
        map.put("data", projectList);
        return AppResult.ok(map);
    }


    @ApiOperation(value = "部门信息列表", notes = "部门信息列表")
    @PostMapping(value = "/departmentList")
    public AppResult<List<Departments>> departmentList() {
        AppResult<List<Departments>> result = new AppResult<List<Departments>>();
        List<Departments> list = departmentsService.list();
        list.sort(new Comparator<Departments>() {
            @Override
            public int compare(Departments o1, Departments o2) {
                if (StringUtils.isNotBlank(o1.getName()) && StringUtils.isNotBlank(o2.getName())) {
                    int t1 = getSort(o1.getName());
                    int t2 = getSort(o2.getName());
                    return t1 - t2;
                }
                return 0;
            }

            private int getSort(String key) {
                Map<String, Integer> sortMap = new HashMap<>();
                sortMap.put("闽清县", 0);
                sortMap.put("梅城镇", 1);
                sortMap.put("梅溪镇", 2);
                sortMap.put("云龙乡", 3);
                sortMap.put("白中镇", 4);
                sortMap.put("白樟镇", 5);
                sortMap.put("池园镇", 6);
                sortMap.put("坂东镇", 7);
                sortMap.put("东桥镇", 8);
                sortMap.put("金沙镇", 9);
                sortMap.put("省璜镇", 10);
                sortMap.put("塔庄镇", 11);
                sortMap.put("上莲乡", 12);
                sortMap.put("雄江镇", 13);
                sortMap.put("三溪乡", 14);
                sortMap.put("桔林乡", 15);
                sortMap.put("下祝乡", 16);
                return sortMap.get(key);
            }
        });
        result.setSuccess(true);
        result.setData(list);
        return result;
    }



    @ApiOperation(value = "项目信息表-分页列表查询", notes = "项目信息表-分页列表查询")
    @PostMapping(value = "/projectList")
    public AppResult<List<ResultProject>> projectList(@RequestBody ProjectDto dto) {
        Project project = new Project();
        AppResult<List<ResultProject>> result = new AppResult<List<ResultProject>>();
        project.setStatus("0");
        int pageno = StringUtils.isBlank(dto.getPageNo()) ? 1 : Integer.valueOf(dto.getPageNo());
        int pagesize = StringUtils.isBlank(dto.getPageSize()) ? 10 : Integer.valueOf(dto.getPageSize());
        if (StringUtils.isNotBlank(dto.getDepartment())&&"0".equals(dto.getDepartment())){
            dto.setDepartment("");
        }
        BeanUtil.copyProperties(dto,project);
        Page<Project> page = new Page<Project>(pageno, pagesize);
        IPage<ResultProject> pageList = projectService.queryAppListProject(page, project);
        result.setSuccess(true);
        result.setData(pageList.getRecords());
        return result;
    }

    @ApiOperation(value = "项目资源类型列表", notes = "项目资源类型")
    @PostMapping(value = "/resourceTypeList")
    public AppResult<List<String>> projectList() {
        AppResult<List<String>> result = new AppResult<>();
        List<String> list = projectService.queryResourceType();
        list = list.stream().filter(e->StringUtils.isNotBlank(e)).collect(Collectors.toList());
        result.setData(list);

        return result;
    }


    @ApiOperation(value = "项目信息表-通过id查询 阅读次数+1", notes = "项目信息表-通过id查询")
    @PostMapping(value = "/queryProjectById")
    public AppResult<Project> queryProjectById(@RequestBody IdDto dto) {
        String id = dto.getId();
        AppResult<Project> result = new AppResult<Project>();
        Project project = projectService.getById(id);
        if (project.getPreferentialPolicy() != null) {
            List<FavorablePolicy> policis = favorablePolicyService.queryListByIds(Arrays.asList(project.getPreferentialPolicy().split(",")));
            project.setFavorablePolicys(policis);
        }
        if (project == null) {
            result.error500("未找到对应实体");
        } else {
            int read = 1;
            if (project.getBrowse() != null) {
                read = project.getBrowse() + 1;
            }
            project.setBrowse(read);
            projectService.updateById(project);
            result.setData(project);
            result.setSuccess(true);
        }
        return result;
    }


    @ApiOperation(value = "项目信息表-通过id查询", notes = "项目信息表-通过id查询")
    @PostMapping(value = "/queryProjectInfoById")
    public AppResult<?> queryProjectInfoById(@RequestBody IdDto dto) {
//        AppResult<ProjectInfo> result = new AppResult<ProjectInfo>();
//        ProjectInfo projectInfo = new ProjectInfo();
//        Project project = projectService.getById(dto.getId());
//        if (ObjectUtil.isEmpty(project)) {
//            result.setCode(500);
//            result.setSuccess(false);
//            result.setMessage("项目不存在");
//            return result;
//        }
//        Departments departments = departmentsService.getById(project.getDepartment());
//        IndustryType industryType = industryTypeService.getById(project.getIndustryType());
//        project.setDepartmentName(departments.getName());
//        ModuleVo moduleVo = new ModuleVo();
//        moduleVo.setId(1);
//        moduleVo.setZu("");
//        moduleVo.setTypeName("优惠政策");
//        project.setIndustryTypeName(industryType.getName());
//        if (project.getPreferentialPolicy() != null) {
//            List<FavorablePolicy> policis = favorablePolicyService.queryListByIds(Arrays.asList(project.getPreferentialPolicy().split(",")));
//            project.setFavorablePolicys(policis);
//            List<ContentVo> contentVoList = new ArrayList<>();
//            for (FavorablePolicy policy : policis) {
//                ContentVo contentVo = new ContentVo();
//                contentVo.setType("text");
//                contentVo.setTitle("");
//                contentVo.setContent(policy.getTitle());
//                contentVoList.add(contentVo);
//            }
//            moduleVo.setList(contentVoList);
//        }
//        String res = project.getProjectMoudle();
//        List<ModuleVo> moduleVoList = JSONUtil.toList(JSONUtil.parseArray(res), ModuleVo.class);
//        for (ModuleVo m : moduleVoList) {
//            if (!"一图一文".equals(m.getTypeName())) {
//                continue;
//            }
//            List<ContentVo> c = m.getList();
//            for (ContentVo vo : c) {
//                if ("input".equals(vo.getType()) && "建设内容与规模".equals(vo.getContent())) {
//                    m.setTypeName("一图一文2");
//                }
//                if ("input".equals(vo.getType()) && "经济社会效益".equals(vo.getContent())) {
//                    m.setTypeName("一图一文3");
//                }
//            }
//        }
////        for (ModuleVo moduleVo : moduleVoList) {
////            if ("一图一文".equals(moduleVo.getTypeName())) {
////
////            }
////        }
//        //  /sys/common/view
//        BeanUtil.copyProperties(project, projectInfo);
//        moduleVoList.add(moduleVo);
//
//
//        projectInfo.setModuleList(moduleVoList);
//        result.setCode(200);
//        result.setData(projectInfo);

        Project project = projectService.getById(dto.getId());
        if (ObjectUtil.isEmpty(project)) {
            return AppResult.error("无法查看详情");
        }
        if ("1".equals(project.getIndustryType()) || "2".equals(project.getIndustryType())){
            Map<String, Object> map = new LinkedHashMap<>();
            List<String> imgList = new ArrayList<>();
            String module = project.getProjectMoudle();
            if (StringUtils.isBlank(module)){
                return AppResult.error("无法查看详情");
            }
            AppResBO appResBO = JSONUtil.toBean(module,AppResBO.class);
            imgList.add(appResBO.getAppImg());
            map.put("imgList", imgList);
            map.put("introduction", appResBO.getAppCotent());
            return AppResult.ok(map);
        } else {
            LambdaQueryWrapper<Plot> qw = new LambdaQueryWrapper<>();
            qw.eq(Plot::getIsParent, "1");
            qw.eq(Plot::getBelong,dto.getId());
            List<Plot> plotList = plotService.list(qw);
            if (plotList.size() == 0) {
                return AppResult.error("未找到地块信息");
            }
            // 归属地
            for (Plot plot : plotList) {
                PlotSummaryBO plotSummaryBO = new PlotSummaryBO();
                //片区 名称照片
                plotSummaryBO.setName(plot.getPlotName());
                if (StringUtils.isBlank(plot.getBelong())){
                    continue;
                }
                project = projectService.getById(plot.getBelong());
                if (ObjectUtil.isEmpty(project)){
                    return AppResult.error("项目不存在");
                }
                String homeimg = StringUtils.isBlank(plot.getPlotImg())? project.getImg():plot.getPlotImg();
                plotSummaryBO.setImg(homeimg);
                //获取片区下的地块
                List<Plot> subPlotList = plotService.list(new LambdaQueryWrapper<Plot>().eq(Plot::getIsParent, "0").eq(Plot::getBelong, plot.getId()));
                int canUsePlot = 0;
                double canUsePlotSize = 0.0;
                List<PlotSummaryListBO> plotSummaryList = new ArrayList<>();
                List<RegionSubBO> regionSubList = new ArrayList<>();
                for (Plot sub : subPlotList) {
                    //可用地块统计
                    if ("0".equals(sub.getUseStatus())) {
                        canUsePlot++;
                        canUsePlotSize += Double.valueOf(sub.getAreaSize());
                    }
                    //
                    PlotSummaryListBO summaryListBO = null;
                    List<PlotTypeBO> plotTypeList = null;
                    for (PlotSummaryListBO listBO : plotSummaryList) {
                        if (listBO.getTitle().equals(sub.getStatus())) {
                            double sumSize = Double.valueOf(listBO.getSumSize()) + Double.valueOf(sub.getAreaSize());
                            listBO.setSumSize(new BigDecimal(sumSize).setScale(2, BigDecimal.ROUND_HALF_UP) + "");
                            plotTypeList = listBO.getPlotTypeList();
                            summaryListBO = listBO;
                        }
                    }
                    if (summaryListBO == null) {
                        summaryListBO = new PlotSummaryListBO();
                        summaryListBO.setTitle(sub.getStatus());
                        summaryListBO.setSumSize(new BigDecimal(Double.valueOf(sub.getAreaSize())).setScale(2, BigDecimal.ROUND_HALF_UP) + "");
                        plotTypeList = new ArrayList<>();

                        summaryListBO.setPlotTypeList(plotTypeList);
                        plotSummaryList.add(summaryListBO);
                    }


                    PlotTypeBO plotTypeBO = null;
                    for (PlotTypeBO typeBO : plotTypeList) {
                        if (typeBO.getPlotType().equals(sub.getPlotType())) {
                            int typeNum = Integer.valueOf(typeBO.getTypeNum()) + 1;
                            double sumSize2 = Double.valueOf(typeBO.getSumSize()) + Double.valueOf(sub.getAreaSize());
                            typeBO.setTypeNum(typeNum + "");
                            typeBO.setSumSize(new BigDecimal(sumSize2).setScale(2, BigDecimal.ROUND_HALF_UP) + "");
                            plotTypeBO = typeBO;
                        }
                    }
                    if (plotTypeBO == null) {
                        plotTypeBO = new PlotTypeBO();
                        plotTypeBO.setPlotType(sub.getPlotType());
                        plotTypeBO.setTypeNum("1");
                        plotTypeBO.setSumSize(new BigDecimal(Double.valueOf(sub.getAreaSize())).setScale(2, BigDecimal.ROUND_HALF_UP) + "");
                        plotTypeList.add(plotTypeBO);
                    }
                    summaryListBO.setPlotTypeList(plotTypeList);


                    RegionSubBO regionSubBO = null;
                    for (RegionSubBO subBO : regionSubList) {
                        if (subBO.getName().equals(sub.getBelongRegion())) {
                            List<PlotBO> plotBoList = subBO.getPlotList();
                            PlotBO plotBO = new PlotBO();
                            plotBO.setPlotName(sub.getPlotName());
                            plotBO.setPlotContent(sub.getPlotContent());
                            plotBoList.add(plotBO);
                            regionSubBO = subBO;
                        }
                    }
                    if (regionSubBO == null) {
                        regionSubBO = new RegionSubBO();
                        regionSubBO.setName(sub.getBelongRegion());
                        regionSubBO.setImg(sub.getPlotImg());
                        List<PlotBO> plotBoList = new ArrayList<PlotBO>();
                        PlotBO plotBO = new PlotBO();
                        plotBO.setPlotName(sub.getPlotName());
                        plotBO.setPlotContent(sub.getPlotContent());
                        plotBoList.add(plotBO);
                        regionSubBO.setPlotList(plotBoList);
                        regionSubList.add(regionSubBO);
                    }

                }
                plotSummaryBO.setCanUsePlot(canUsePlot + "");
                plotSummaryBO.setCanUsePlotSize(new BigDecimal(Double.valueOf(canUsePlotSize)).setScale(2, BigDecimal.ROUND_HALF_UP) + "");
                plotSummaryBO.setRegionSubList(regionSubList);
                plotSummaryBO.setPlotSummaryList(plotSummaryList);
              return AppResult.ok(plotSummaryBO);
            }
        }
        return AppResult.error("无法查看详情");
    }


    @ApiOperation(value = "招商成员查询", notes = "招商成员查询")
    @PostMapping(value = "/member")
    public AppResult<Member> member() {
        List<Member> memberList = memberService.list(new LambdaQueryWrapper<Member>().eq(Member::getStatus, "1").last("limit 1"));
        AppResult<Member> result = new AppResult<Member>();
        Member member = null;
        if (memberList.size() > 0) {
            member = memberList.get(0);
        }
        result.setData(member);
        result.setSuccess(true);
        return result;
    }

    @ApiOperation(value = "产业链信息-分页列表查询", notes = "产业链信息-分页列表查询")
    @PostMapping(value = "/industryChainList")
    public AppResult<List<IndustryChain>> industryChainList(@RequestBody IndustryChainDto dto) {
        AppResult<List<IndustryChain>> result = new AppResult<List<IndustryChain>>();
        LambdaQueryWrapper<IndustryChain> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(dto.getType())) {
            queryWrapper.eq(IndustryChain::getType, dto.getType());
        }
        int pageno = StringUtils.isBlank(dto.getPageNo()) ? 1 : Integer.valueOf(dto.getPageNo());
        int pagesize = StringUtils.isBlank(dto.getPageSize()) ? 1000 : Integer.valueOf(dto.getPageSize());
        Page<IndustryChain> page = new Page<IndustryChain>(pageno, pagesize);
        IPage<IndustryChain> pageList = industryChainService.page(page, queryWrapper);
        List<IndustryChain> pageListRecords = pageList.getRecords();
        for (IndustryChain chain : pageListRecords) {
            if (StringUtils.isBlank(chain.getReadTime())) {
                chain.setReadTime("0");
            }
        }
        pageList.setRecords(pageListRecords);
        result.setSuccess(true);
        result.setData(pageListRecords);
        return result;
    }

    @ApiOperation(value = "产业链信息-通过id查询 阅读次数+1", notes = "产业链信息-通过id查询")
    @PostMapping(value = "/queryIndustryChainById")
    public AppResult<IndustryChain> queryIndustryChainById(@RequestBody IdDto dto) {
        String id = dto.getId();
        AppResult<IndustryChain> result = new AppResult<IndustryChain>();
        IndustryChain industryChain = industryChainService.getById(id);
        if (industryChain == null) {
            result.error500("未找到对应实体");
        } else {
            int read = 1;
            if (StringUtils.isNotBlank(industryChain.getReadTime())) {
                read = Integer.valueOf(industryChain.getReadTime()) + 1;
            }
            industryChain.setReadTime(read + "");
            industryChainService.updateById(industryChain);
            result.setData(industryChain);
            result.setSuccess(true);
        }
        return result;
    }

    @ApiOperation(value = "优惠政策/政策扶持-列表查询 --方式1：获取树状结构", notes = "优惠政策-列表查询")
    @PostMapping(value = "/favorablePolicyTree")
    public AppResult<List<FavorablePolicy>> favorablePolicyTree() {
        AppResult<List<FavorablePolicy>> result = new AppResult<List<FavorablePolicy>>();
        List<FavorablePolicy> list = favorablePolicyService.builTree();
        result.setSuccess(true);
        result.setData(list);
        return result;
    }

    @ApiOperation(value = "优惠政策/政策扶持-列表查询 --方式2：根据根名称获取", notes = "优惠政策-列表查询")
    @PostMapping(value = "/favorablePolicyList")
    public AppResult<List<FavorablePolicy>> favorablePolicyList(@RequestBody FavorablePolicyDto dto) {
        String parentName = dto.getParentName();
        AppResult<List<FavorablePolicy>> result = new AppResult<List<FavorablePolicy>>();
        List<FavorablePolicy> list = null;
        if (StringUtils.isNotBlank(parentName)) {
            LambdaQueryWrapper<FavorablePolicy> qw = new LambdaQueryWrapper<>();
            qw.eq(FavorablePolicy::getTitle, parentName);
            FavorablePolicy parentNode = favorablePolicyService.getOne(qw);
            if (ObjectUtil.isEmpty(parentNode)) {
                list = new ArrayList<FavorablePolicy>();
            } else {
                qw = new LambdaQueryWrapper<>();
                qw.eq(FavorablePolicy::getParentId, parentNode.getId());
                favorablePolicyService.list(qw);
                list = favorablePolicyService.list(qw);
            }
        } else {
            LambdaQueryWrapper<FavorablePolicy> qw = new LambdaQueryWrapper<>();
            qw.ne(FavorablePolicy::getParentId, "0");
            list = favorablePolicyService.list(qw);
        }
        result.setSuccess(true);
        result.setData(list);
        return result;
    }

    @ApiOperation(value = "优惠政策/政策扶持-通过id查询  阅读次数+1", notes = "优惠政策-通过id查询")
    @PostMapping(value = "/queryFavorablePolicyById")
    public AppResult<FavorablePolicy> queryFavorablePolicyById(@RequestBody IdDto dto) {
        String id = dto.getId();
        AppResult<FavorablePolicy> result = new AppResult<FavorablePolicy>();
        FavorablePolicy favorablePolicy = favorablePolicyService.getById(id);
        if (favorablePolicy == null) {
            result.error500("未找到对应实体");
        } else {
            int read = 1;
            if (StringUtils.isNotBlank(favorablePolicy.getReadTime())) {
                read = Integer.valueOf(favorablePolicy.getReadTime()) + 1;
            }
            favorablePolicy.setReadTime(read + "");
            favorablePolicyService.updateById(favorablePolicy);
            result.setData(favorablePolicy);
            result.setSuccess(true);
        }
        return result;
    }


    @ApiOperation(value = "招商工作动态-分页列表查询", notes = "招商工作动态-分页列表查询")
    @PostMapping(value = "/dynamicNewsList")
    public AppResult<List<DynamicNews>> queryPageList(@RequestBody DynamicNewsDto dto) {
        DynamicNews dynamicNews = new DynamicNews();
        AppResult<List<DynamicNews>> result = new AppResult<List<DynamicNews>>();
        int pageno = StringUtils.isBlank(dto.getPageNo()) ? 1 : Integer.valueOf(dto.getPageNo());
        int pagesize = StringUtils.isBlank(dto.getPageSize()) ? 10 : Integer.valueOf(dto.getPageSize());
        Page<DynamicNews> page = new Page<DynamicNews>(pageno, pagesize);
        IPage<DynamicNews> pageList = dynamicNewsService.getPage(page, dynamicNews);
        List<DynamicNews> pageListRecords = pageList.getRecords();
        for (DynamicNews news : pageListRecords) {
//            if (news.getCreateTime() != null) {
//                news.setCreateTime(DateUtil.parse(DateUtil.format(news.getCreateTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
//            }
//            if (news.getUpdateTime() != null) {
//                news.setUpdateTime(DateUtil.parse(DateUtil.format(news.getUpdateTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
//            }
            if (StringUtils.isBlank(news.getPraise())) {
                news.setPraise("0");
            }
            if (StringUtils.isBlank(news.getReadTime())) {
                news.setReadTime("0");
            }
            if (StringUtils.isBlank(dto.getImei()) || "null".equals(dto.getImei())) {
                news.setType("0");
            } else {
                LambdaQueryWrapper<PraiseLog> qw = new LambdaQueryWrapper();
                qw.eq(PraiseLog::getImei, dto.getImei());
                qw.eq(PraiseLog::getNid, news.getId());
                qw.eq(PraiseLog::getName, "动态新闻");
                PraiseLog praiseLog = praiseLogService.getOne(qw);
                if (ObjectUtil.isEmpty(praiseLog)) {
                    news.setType("0");
                } else {
                    news.setType(praiseLog.getType());
                }
            }
        }
        pageList.setRecords(pageListRecords);
        result.setSuccess(true);
        result.setData(pageListRecords);
        return result;
    }




    @ApiOperation(value = "招商工作动态-通过id查询 阅读次数+1", notes = "招商工作动态-通过id查询")
    @PostMapping(value = "/queryDynamicNewsById")
    public AppResult<DynamicNews> queryDynamicNewsById(@RequestBody IdDto dto) {
        String id = dto.getId();
        AppResult<DynamicNews> result = new AppResult<DynamicNews>();
        DynamicNews dynamicNews = dynamicNewsService.getById(id);
        if (dynamicNews == null) {
            result.error500("未找到对应实体");
        } else {
            int read = 1;
            if (StringUtils.isNotBlank(dynamicNews.getReadTime())) {
                read = Integer.valueOf(dynamicNews.getReadTime()) + 1;
            }
            dynamicNews.setReadTime(read + "");
            dynamicNewsService.updateById(dynamicNews);
            result.setData(dynamicNews);
            result.setSuccess(true);
        }
        return result;
    }

    /**
     * @param dto type  0 取消 1 点赞
     * @return
     */
    @ApiOperation(value = "招商工作动态 通过id  点赞次数 0 取消 1 点赞", notes = "点赞次数+1")
    @PostMapping(value = "/addDynamicNewsPraise")
    public AppResult<?> addDynamicNewsPraise(@RequestBody AddPraiseDto dto) {
        String id = dto.getId();
        String imei = dto.getImei();
        String type = dto.getType();
        DynamicNews news = dynamicNewsService.getById(id);
        LambdaQueryWrapper<PraiseLog> qw = new LambdaQueryWrapper();
        qw.eq(PraiseLog::getImei, imei);
        qw.eq(PraiseLog::getNid, id);
        qw.eq(PraiseLog::getName, "动态新闻");
        PraiseLog praiseLog = praiseLogService.getOne(qw);
        int praise = 0;
        String msg = "";
        if (StringUtils.isBlank(imei) || "null".equals(imei)) {
            return AppResult.error("请开通获取IMEI权限");
        }
        if (ObjectUtil.isEmpty(news)) {
            return AppResult.error("该条动态不存在");
        } else {
            String praiseStr = news.getPraise();
            if (StringUtils.isNotBlank(praiseStr)) {
                praise = Integer.valueOf(praiseStr);
            }
        }
        switch (type) {
            case "0":
                if (ObjectUtil.isEmpty(praiseLog) || "0".equals(praiseLog.getType())) {
                    return AppResult.error("未点赞");
                }
                praiseLog.setType("0");
                praiseLogService.updateById(praiseLog);
                msg = "取消成功";
                praise -= 1;
                break;
            case "1":
                if (ObjectUtil.isEmpty(praiseLog)) {
                    praiseLog = new PraiseLog();
                    praiseLog.setType("1");
                    praiseLog.setName("动态新闻");
                    praiseLog.setImei(imei);
                    praiseLog.setNid(id);
                    praiseLog.setId(UUIDGenerator.generate());
                    praiseLogService.save(praiseLog);
                } else if ("0".equals(praiseLog.getType())) {
                    praiseLog.setType("1");
                    praiseLogService.updateById(praiseLog);
                } else {
                    return AppResult.error("已点赞");
                }
                msg = "点赞成功";
                praise += 1;
                break;
            default:

        }
        news.setPraise(praise + "");
        dynamicNewsService.updateById(news);
        return AppResult.ok(msg);
    }


    @ApiOperation(value = "闽清公告-分页列表查询", notes = "闽清公告-分页列表查询")
    @PostMapping(value = "/announcementList")
    public AppResult<List<Announcement>> queryPageList(@RequestBody ReqPage dto) {
        AppResult<List<Announcement>> result = new AppResult<List<Announcement>>();
        LambdaQueryWrapper<Announcement> queryWrapper = new LambdaQueryWrapper<>();
        int pageno = StringUtils.isBlank(dto.getPageNo()) ? 1 : Integer.valueOf(dto.getPageNo());
        int pagesize = StringUtils.isBlank(dto.getPageSize()) ? 10 : Integer.valueOf(dto.getPageSize());
        Page<Announcement> page = new Page<Announcement>(pageno, pagesize);
        IPage<Announcement> pageList = announcementService.page(page, queryWrapper);
        result.setSuccess(true);
        result.setData(pageList.getRecords());
        return result;
    }


    @ApiOperation(value = "闽清公告-通过id查询 阅读次数+1", notes = "闽清公告-通过id查询")
    @PostMapping(value = "/queryAnnouncementById")
    public AppResult<Announcement> queryAnnouncementById(@RequestBody IdDto dto) {
        String id = dto.getId();
        AppResult<Announcement> result = new AppResult<Announcement>();
        Announcement announcement = announcementService.getById(id);
        if (announcement == null) {
            result.error500("未找到对应实体");
        } else {
            int read = 1;
            if (StringUtils.isNotBlank(announcement.getReadTime())) {
                read = Integer.valueOf(announcement.getReadTime()) + 1;
            }
            announcement.setReadTime(read + "");
            announcementService.updateById(announcement);
            result.setData(announcement);
            result.setSuccess(true);
        }
        return result;
    }


    @ApiOperation(value = "资源分布管理-列表查询", notes = "资源分布管理-列表查询")
    @PostMapping(value = "/resourceManageList")
    public AppResult<List<ResourceManage>> queryPageList(@RequestBody SearchDto dto) {
        AppResult<List<ResourceManage>> result = new AppResult<List<ResourceManage>>();
        LambdaQueryWrapper<ResourceManage> queryWrapper = new LambdaQueryWrapper();
        result.setSuccess(true);
        if (StringUtils.isNotBlank(dto.getSearch())) {
            queryWrapper.like(ResourceManage::getTitle,dto.getSearch());
        }
        if (StringUtils.isNotBlank(dto.getDepartment())){
            queryWrapper.eq(ResourceManage::getDepartment,dto.getDepartment());
        }
        if (StringUtils.isNotBlank(dto.getIndustryType())){
            queryWrapper.eq(ResourceManage::getIndustryType,dto.getIndustryType());
        }
        result.setData(resourceManageService.list(queryWrapper));
        return result;
    }

    @ApiOperation(value = "获取 农业 自然资源 列表", notes = "获取 农业 自然资源列表")
    @PostMapping(value = "/queryLandNaturalByType")
    public AppResult<List<LandNaturalBo>> queryLandNaturalByType(@Valid @RequestBody TypeDto dto) {
        AppResult<List<LandNaturalBo>> result = new AppResult<>();
        List<LandNaturalBo> resList = new ArrayList<>();
        if (StringUtils.isBlank(dto.getType())) {
            return result.error500("type不能为空 0 农业 1自然 3工业（土地）");
        }
        if ("0".equals(dto.getType())) {
            LandNaturalBo bo = new LandNaturalBo();
            List<Project> projects = projectService.list(new LambdaQueryWrapper<Project>().eq(Project::getIndustryType, "1"));
            bo.setTitle("农业资源");
            List<AppResBO> sonList = new ArrayList<>();
            if (projects.size() > 0) {
                for (Project tmp:projects){
                    if (StringUtils.isBlank(tmp.getProjectMoudle())){
                        continue;
                    }
                    String module = tmp.getProjectMoudle();
                    try {
                        AppResBO appResBO = JSONUtil.toBean(module,AppResBO.class);
                        if (ObjectUtil.isNotEmpty(appResBO)){
                            sonList.add(appResBO);
                        }
                    } catch (Exception e){
                        continue;
                    }
                }
            }
            bo.setSonList(sonList);
            if (sonList.size()>0){
                bo.setImg(sonList.get(0).getAppImg());
            }
            bo.setProjectList(projects);
            resList.add(bo);
        } else if ("1".equals(dto.getType())) {
            Map<String,String> picmap = new HashMap<>();
            picmap.put("工业用地","files/20200308/icon_工业用地.png");
            picmap.put("古厝篇","files/20200308/icon_古厝.png");
            picmap.put("红色篇","files/20200308/icon_红色篇.png");
            picmap.put("居住用地","files/20200308/icon_居住用地.png");
            picmap.put("农业篇","files/20200308/icon_农业篇.png");
            picmap.put("其他","files/20200308/icon_其他.png");
            picmap.put("商务用地","files/20200308/icon_商务用地.png");
            picmap.put("温泉篇","files/20200308/icon_温泉.png");
            picmap.put("文化人物篇","files/20200308/icon_文化人物.png");
            picmap.put("乡村旅游篇","files/20200308/icon_乡村旅游.png");
            picmap.put("自然景观篇","files/20200308/icon_自然景观.png");
            List<String> types = projectService.queryResourceType();
            for (String type:types){
                if(StringUtils.isBlank(type)){
                    continue;
                }
                List<Project> projects = projectService.list(new LambdaQueryWrapper<Project>().eq(Project::getIndustryType, "2").eq(Project::getResourceType,type));
                LandNaturalBo bo = new LandNaturalBo();
                bo.setTitle(type);
                bo.setImg(picmap.get(type));
                List<AppResBO> sonList = new ArrayList<>();
                if (projects.size() > 0) {
                    for (Project tmp:projects){
                        if (StringUtils.isBlank(tmp.getProjectMoudle())){
                            continue;
                        }
                        String module = tmp.getProjectMoudle();
                        try {
                            AppResBO appResBO = JSONUtil.toBean(module,AppResBO.class);
                            if (ObjectUtil.isNotEmpty(appResBO)){
                                sonList.add(appResBO);
                            }
                        } catch (Exception e){
                            continue;
                        }
                    }
                }
                bo.setSonList(sonList);
                bo.setProjectList(projects);
                resList.add(bo);
            }
        } else {
            return result.error500("type 类型错误 0农业 1 自然");
        }
        result.setData(resList);
        return result;
    }

    @ApiOperation(value = "查看图片", notes = "查看图片")
    @GetMapping(value = "/view/**")
    public void view(HttpServletRequest request, HttpServletResponse response) {
        // ISO-8859-1 ==> UTF-8 进行编码转换
        String imgPath = extractPathFromPattern(request);
        // 其余处理略
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            imgPath = imgPath.replace("..", "");
            if (imgPath.endsWith(",")) {
                imgPath = imgPath.substring(0, imgPath.length() - 1);
            }
            response.setContentType("image/jpeg;charset=utf-8");
            String localPath = uploadpath;
            String imgurl = localPath + File.separator + imgPath;
            inputStream = new BufferedInputStream(new FileInputStream(imgurl));
            outputStream = response.getOutputStream();
            byte[] buf = new byte[1024];
            int len;
            while ((len = inputStream.read(buf)) > 0) {
                outputStream.write(buf, 0, len);
            }
            response.flushBuffer();
        } catch (IOException e) {
            log.error("预览图片失败" + e.getMessage());
            // e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    log.error(e.getMessage(), e);
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    //log.error(e.getMessage(), e);
                }
            }
        }

    }

    private static String extractPathFromPattern(final HttpServletRequest request) {
        String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
        String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
        return new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path);
    }

    @GetMapping(value = "/video/**")
    public void video(HttpServletRequest request, HttpServletResponse response) {
        // ISO-8859-1 ==> UTF-8 进行编码转换
        String imgPath = extractPathFromPattern(request);
        // 其余处理略
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            imgPath = imgPath.replace("..", "");
            if (imgPath.endsWith(",")) {
                imgPath = imgPath.substring(0, imgPath.length() - 1);
            }
//            response.setContentType("video/mpeg4;charset=utf-8");
            String localPath = uploadpath;
            String imgurl = localPath + File.separator + imgPath;
            inputStream = new BufferedInputStream(new FileInputStream(imgurl));
            outputStream = response.getOutputStream();
            byte[] buf = new byte[1024];
            int len;
            while ((len = inputStream.read(buf)) > 0) {
                outputStream.write(buf, 0, len);
            }
            response.flushBuffer();
        } catch (IOException e) {
            log.error("预览视频失败" + e.getMessage());
            // e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    log.error(e.getMessage(), e);
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    //log.error(e.getMessage(), e);
                }
            }
        }

    }


    @GetMapping("/videoView")
    public ModelAndView videoView(@RequestParam String video) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("videoView");
        log.info("--------------video--------------");
        //files/20200211/yiqing205200.mp4
        modelAndView.addObject("video", video);
        return modelAndView;
    }


    @GetMapping("/otherView")
    public ModelAndView otherView(@RequestParam String type) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("otherView");
        List<OtherService> otherServices = otherServiceService.list();
        if ("1".equals(type)) {
            modelAndView.addObject("other", otherServices.get(0).getProduction());
        } else if ("2".equals(type)) {
            modelAndView.addObject("other", otherServices.get(0).getInvestment());
        }
        return modelAndView;
    }


    @ApiOperation(value = "获取安卓版本", notes = "获取安卓版本")
    @PostMapping(value = "/apkVersion/detailApkVersion")
    public AppResult<?> apkVersion(@RequestBody ApkVersionDto dto) {
        log.info(dto.getApkVersion());
        if (StringUtils.isBlank(dto.getApkVersion())) {
            return AppResult.error("版本号为空");
        }
        long version = Long.valueOf(dto.getApkVersion());
        Map<String, Object> map = new HashMap<>();
        String imgPath = "apk/minqing-release.apk";
        String localPath = uploadpath;
        String imgurl = localPath + File.separator + imgPath;
        Map<String, Object> apkdata = readApk(new File(imgurl));
        try {
            if (version < (Long) apkdata.get("versioncode")) {
                map.put("url", "apk/minqing-release.apk");
                return AppResult.ok(map);
            }
        } catch (Exception e) {
            return AppResult.error("无法获取版本号");
        }
        return AppResult.error("已经是最新版,无需更新");
    }


    @ApiOperation(value = "获取安卓版本 e码通", notes = "获取安卓版本 e码通")
    @PostMapping(value = "/apkVersion/detailApkVersion/emt")
    public AppResult<?> emtapkVersion(@RequestBody ApkVersionDto dto) {
        log.info(dto.getApkVersion());
        if (StringUtils.isBlank(dto.getApkVersion())) {
            return AppResult.error("版本号为空");
        }
        long version = Long.valueOf(dto.getApkVersion());
        Map<String, Object> map = new HashMap<>();
        String imgPath = "apk/emt-release.apk";
        String localPath = uploadpath;
        String imgurl = localPath + File.separator + imgPath;
        Map<String, Object> apkdata = readApk(new File(imgurl));
        try {
            if (version < (Long) apkdata.get("versioncode")) {
                map.put("url", "apk/emt-release.apk");
                return AppResult.ok(map);
            }
        } catch (Exception e) {
            return AppResult.error("无法获取版本号");
        }
        return AppResult.error("已经是最新版,无需更新");
    }


    @GetMapping(value = "/downloadNewApk/**")
    public void downloadNewApk(HttpServletRequest request, HttpServletResponse response) {
        String imgPath = extractPathFromPattern(request);
        // 其余处理略
//        InputStream inputStream = null;
//        OutputStream outputStream = null;
        try {
            imgPath = imgPath.replace("..", "");
            if (imgPath.endsWith(",")) {
                imgPath = imgPath.substring(0, imgPath.length() - 1);
            }
//            response.setContentType("video/mpeg4;charset=utf-8");
            String localPath = uploadpath;
            String imgurl = localPath + File.separator + imgPath;
            File file = FileUtil.file(imgurl);
            long size = FileUtil.size(file);
            int s = Integer.valueOf(Long.toString(size));
            response.setContentLength(s);
//            inputStream = new BufferedInputStream(new FileInputStream(imgurl));
//            outputStream = response.getOutputStream();
//            byte[] buf = new byte[1024];
//            int len;
//            while ((len = inputStream.read(buf)) > 0) {
//                outputStream.write(buf, 0, len);
//            }
//            response.flushBuffer();
            FileUtil.writeToStream(file, response.getOutputStream());
        } catch (IOException e) {
            log.error("下载apk失败" + e.getMessage());
            // e.printStackTrace();
        } finally {
//            if (inputStream != null) {
//                try {
//                    inputStream.close();
//                } catch (IOException e) {
//                    log.error(e.getMessage(), e);
//                }
//            }
//            if (outputStream != null) {
//                try {
//                    outputStream.close();
//                } catch (IOException e) {
//                    //log.error(e.getMessage(), e);
//                }
//            }
        }

    }

    public static Map<String, Object> readApk(File apkUrl) {
        Map<String, Object> resMap = new HashMap<String, Object>();
        try (ApkFile apkFile = new ApkFile(apkUrl)) {
            ApkMeta apkMeta = apkFile.getApkMeta();
            resMap.put("filename", apkMeta.getName());
            resMap.put("pkgname", apkMeta.getPackageName());
            resMap.put("versioncode", apkMeta.getVersionCode());
            resMap.put("versionname", apkMeta.getVersionName());
            for (UseFeature feature : apkMeta.getUsesFeatures()) {
                System.out.println(feature.getName());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return resMap;
    }

    @ApiOperation(value = "其他服务-分页列表查询", notes = "其他服务-分页列表查询")
    @PostMapping(value = "/otherServiceList")
    public AppResult<OtherService> otherServiceList() {
        AppResult<OtherService> result = new AppResult<>();
        List<OtherService> otherServices = otherServiceService.list();
        if (otherServices.size() > 0) {
            result.setData(otherServices.get(0));
        } else {
            result.setData(new OtherService());
        }
        result.setSuccess(true);
        result.setCode(200);
        return result;
    }

    @ApiOperation(value = "获取 所有地块  统计", notes = "根据归属 获取片区下 所有地块")
    @PostMapping(value = "/queryPlotSummary")
    public AppResult<PlotSummary> queryPlotSummary(@RequestBody IdDto dto) {
        AppResult<PlotSummary> result = new AppResult<>();
        PlotSummary plotSummary = new PlotSummary();
        //归属地列表
        Project project = null;
        LambdaQueryWrapper<Plot> qw = new LambdaQueryWrapper<>();
        qw.eq(Plot::getIsParent, "1");
        if (StringUtils.isNotBlank(dto.getId())){
            project = projectService.getById(dto.getId());
            if (ObjectUtil.isEmpty(project)){
                return result.error500("项目不存在");
            }
            qw.eq(Plot::getBelong,dto.getId());
        }
        List<Plot> plotList = plotService.list(qw);
        if (plotList.size() == 0) {
            return result.error500("未找到地块信息");
        }
        // 归属地
        List<PlotSummaryBO> summaryList = new ArrayList<>();
        for (Plot plot : plotList) {
            PlotSummaryBO plotSummaryBO = new PlotSummaryBO();
            //片区 名称照片
            plotSummaryBO.setName(plot.getPlotName());
            if (StringUtils.isBlank(plot.getBelong())){
                continue;
            }
            project = projectService.getById(plot.getBelong());
            if (ObjectUtil.isEmpty(project)){
                return result.error500("项目不存在");
            }
            String homeimg = StringUtils.isBlank(plot.getPlotImg())? project.getImg():plot.getPlotImg();
            plotSummaryBO.setImg(homeimg);
            //获取片区下的地块
            List<Plot> subPlotList = plotService.list(new LambdaQueryWrapper<Plot>().eq(Plot::getIsParent, "0").eq(Plot::getBelong, plot.getId()));
            int canUsePlot = 0;
            double canUsePlotSize = 0.0;
            List<PlotSummaryListBO> plotSummaryList = new ArrayList<>();
            List<RegionSubBO> regionSubList = new ArrayList<>();
            for (Plot sub : subPlotList) {
                //可用地块统计
                if ("0".equals(sub.getUseStatus())) {
                    canUsePlot++;
                    canUsePlotSize += Double.valueOf(sub.getAreaSize());
                }
                //
                PlotSummaryListBO summaryListBO = null;
                List<PlotTypeBO> plotTypeList = null;
                for (PlotSummaryListBO listBO : plotSummaryList) {
                    if (listBO.getTitle().equals(sub.getStatus())) {
                        double sumSize = Double.valueOf(listBO.getSumSize()) + Double.valueOf(sub.getAreaSize());
                        listBO.setSumSize(new BigDecimal(sumSize).setScale(2, BigDecimal.ROUND_HALF_UP) + "");
                        plotTypeList = listBO.getPlotTypeList();
                        summaryListBO = listBO;
                    }
                }
                if (summaryListBO == null) {
                    summaryListBO = new PlotSummaryListBO();
                    summaryListBO.setTitle(sub.getStatus());
                    summaryListBO.setSumSize(new BigDecimal(Double.valueOf(sub.getAreaSize())).setScale(2, BigDecimal.ROUND_HALF_UP) + "");
                    plotTypeList = new ArrayList<>();

                    summaryListBO.setPlotTypeList(plotTypeList);
                    plotSummaryList.add(summaryListBO);
                }


                PlotTypeBO plotTypeBO = null;
                for (PlotTypeBO typeBO : plotTypeList) {
                    if (typeBO.getPlotType().equals(sub.getPlotType())) {
                        int typeNum = Integer.valueOf(typeBO.getTypeNum()) + 1;
                        double sumSize2 = Double.valueOf(typeBO.getSumSize()) + Double.valueOf(sub.getAreaSize());
                        typeBO.setTypeNum(typeNum + "");
                        typeBO.setSumSize(new BigDecimal(sumSize2).setScale(2, BigDecimal.ROUND_HALF_UP) + "");
                        plotTypeBO = typeBO;
                    }
                }
                if (plotTypeBO == null) {
                    plotTypeBO = new PlotTypeBO();
                    plotTypeBO.setPlotType(sub.getPlotType());
                    plotTypeBO.setTypeNum("1");
                    plotTypeBO.setSumSize(new BigDecimal(Double.valueOf(sub.getAreaSize())).setScale(2, BigDecimal.ROUND_HALF_UP) + "");
                    plotTypeList.add(plotTypeBO);
                }
                summaryListBO.setPlotTypeList(plotTypeList);


                RegionSubBO regionSubBO = null;
                for (RegionSubBO subBO : regionSubList) {
                    if (subBO.getName().equals(sub.getBelongRegion())) {
                        List<PlotBO> plotBoList = subBO.getPlotList();
                        PlotBO plotBO = new PlotBO();
                        plotBO.setPlotName(sub.getPlotName());
                        plotBO.setPlotContent(sub.getPlotContent());
                        plotBoList.add(plotBO);
                        regionSubBO = subBO;
                    }
                }
                if (regionSubBO == null) {
                    regionSubBO = new RegionSubBO();
                    regionSubBO.setName(sub.getBelongRegion());
                    regionSubBO.setImg(sub.getPlotImg());
                    List<PlotBO> plotBoList = new ArrayList<PlotBO>();
                    PlotBO plotBO = new PlotBO();
                    plotBO.setPlotName(sub.getPlotName());
                    plotBO.setPlotContent(sub.getPlotContent());
                    plotBoList.add(plotBO);
                    regionSubBO.setPlotList(plotBoList);
                    regionSubList.add(regionSubBO);
                }

            }
            plotSummaryBO.setCanUsePlot(canUsePlot + "");
            plotSummaryBO.setCanUsePlotSize(new BigDecimal(Double.valueOf(canUsePlotSize)).setScale(2, BigDecimal.ROUND_HALF_UP) + "");
            plotSummaryBO.setRegionSubList(regionSubList);
            plotSummaryBO.setPlotSummaryList(plotSummaryList);
            summaryList.add(plotSummaryBO);
        }
//        List<PlotSummaryBO> copyList = new ArrayList<>();
//        for (PlotSummaryBO copy : summaryList) {
//            copyList.add(copy);
//        }
//        summaryList.addAll(copyList);
        plotSummary.setSummaryList(summaryList);
        result.setData(plotSummary);
        return result;
    }




}
